package top.system.dept.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import top.system.dept.pojo.Dept;
import top.system.dept.pojo.SysResp;
import top.system.dept.service.DeptService;

/**
 * @ClassName: DeptController
 * @Author: Amosen
 * @Since: 2021/5/22
 */

@Controller
@RequestMapping("/dept")
@ResponseBody
public class DeptController {

    @Autowired
    DeptService deptService;

    @RequestMapping("/get")
    public SysResp getDept(@RequestParam(value = "all", required = false) boolean all,
                           @RequestParam(value = "deptId", required = false) Integer deptId) {
        return deptService.getDept(all, deptId);
    }

    @RequestMapping("/add")
    public SysResp addDept(@RequestParam("userModal") String userModal, Dept dept) {
        return deptService.addDept(userModal, dept);
    }

    @RequestMapping("/delete")
    public SysResp deleteDept(@RequestParam("userModal") String userModal, @RequestParam("deptId") Integer deptId) {
        Dept dept = new Dept();
        dept.setId(deptId);
        return deptService.deleteDept(userModal, dept);
    }

    @RequestMapping("/update")
    public SysResp updateDept(@RequestParam("userModal") String userModal, Dept dept) {
        return deptService.updateDept(userModal, dept);
    }

}
